package pers.wensheng.patterns.behavioral_pattern.observer_pattern.jdk_impl;

import pers.wensheng.patterns.behavioral_pattern.observer_pattern.jdk_impl.entity.Policemen;
import pers.wensheng.patterns.behavioral_pattern.observer_pattern.jdk_impl.entity.Thief;

/**
 * jdk提供的类和接口实现观察者模式
 * 被观察者接口：Observable
 *      protected synchronized void setChanged()                设置改对象被更改为true
 *      public void notifyObservers()                           当对象被更改为true的时候，调用此方法会通知观察者
 *      public synchronized void addObserver(Observer o)        添加观察者
 * 观察者的接口：Observer
 */
public class Client {
    public static void main(String[] args) {
        Thief sun = new Thief("sun");
        Policemen policemen = new Policemen("wen");
        //让警察盯着小偷
        sun.addObserver(policemen);

        //小偷偷东西
        sun.steal();
    }
}
